﻿
-----------------------------------------------------------------------
-- MatrixAddon.lua
--
-- A Framework for World Of Warcraft addons
-- Copyright (C) 2007  wwkkii
-- 
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- any later version.
-- 
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
-- 
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.
-- 
-- Home Page: http://code.google.com/p/wowmatrix
-----------------------------------------------------------------------

local __version__ = { "MatrixAddon", 0, 1, 1 };
if (MatrixUpdateVersion(__version__)) then return; end

-------------------------------------------------------------------------------
-- local variables
-------------------------------------------------------------------------------

local matrix_modules = { };
local matrix_applets = { };

-------------------------------------------------------------------------------
-- matrix Functions
-------------------------------------------------------------------------------

matrix.GetModule = function(key)
	return matrix_modules[key];
end

matrix.GetModuleCount = function()
	return #matrix_modules;
end

matrix.GetApplet = function(idx)
	return matrix_applets[idx];
end

matrix.GetAppletCount = function()
	return #matrix_applets;
end

-------------------------------------------------------------------------------
-- MatrixAddon Class
-------------------------------------------------------------------------------

MatrixClass("MatrixAddon", MatrixObject, MATRIX_VIRTUAL_CLASS);

function MatrixAddon:Initial()
	local class = self:Class();
	self:Super(class.__name__);
end

-------------------------------------------------------------------------------
-- MatrixModule Class
-------------------------------------------------------------------------------

MatrixClass("MatrixModule", MatrixAddon, MATRIX_VIRTUAL_CLASS);

function MatrixModule:Initial()
	local pos;

	self:Super();
	if (MatrixCommon[self:Name()]) then
		self:Crash("ERROR_NAME_CONFLICT", "Module", self:Name());
	end
	matrix.Print("Here create module:"..self:Name());
	pos = #matrix_modules + 1;
	matrix_modules[pos] = self;
	MatrixCommon[self:Name()] = self;
end

function MatrixModule:Final()
	local idx;

	if (MatrixCommon[self:Name()] == self) then
		MatrixCommon[self:Name()] = nil;
	end
	for idx = 1, #matrix_modules, 1 do
		if (matrix_modules[idx] == self) then
			tremove(matrix_modules, idx);
			return;
		end
	end
end

function MatrixModule:OnActive()
end

-------------------------------------------------------------------------------
-- MatrixApplet Class
-------------------------------------------------------------------------------

MatrixClass("MatrixApplet", MatrixAddon, MATRIX_VIRTUAL_CLASS);

MatrixApplet.__children__ = { };

function MatrixApplet:Initial()
	self:Super();
	matrix_applets[#matrix_applets + 1] = self;
end

function MatrixApplet:Final()
	local idx;

	for idx = 1, #matrix_applets, 1 do
		if (matrix_applets[idx] == self) then
			tremove(matrix_applets, idx);
			return;
		end
	end
end

function MatrixApplet:OnEnable()
end

function MatrixApplet:OnDisable()
end

function MatrixApplet:OnReset()
end
